package com.edol.painting.main;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.edol.painting.PainterConfig;
import com.edol.painting.R;

/*  =======================================================================================
 *  Copyright (C) 2017 dlboard.com. All rights reserved.
 *
 *  This computer program source code file is protected by copyright law and international
 *  treaties. Unauthorized distribution of source code files, programs, or portion of the
 *  package, may result in severe civil and criminal penalties, and will be prosecuted to
 *  the maximum extent under the law.
 *
 *  ---------------------------------------------------------------------------------------
 * Author:Administrator
 * Date:2017/7/20
 * Desc:
 *
 * ======================================================================================== */
public class AboutUsActivity extends FragmentActivity implements View.OnClickListener {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);

        TextView appVersionTv = (TextView) findViewById(R.id.app_version);
        String appName = getString(R.string.app_name);
        appVersionTv.setText(appName + "V" + getAppVersionName());

        TextView qqGroupTv = (TextView)findViewById(R.id.qq_group);
        TextView qqTv = (TextView)findViewById(R.id.qq);

        qqGroupTv.setOnClickListener(this);
        qqTv.setOnClickListener(this);
        findViewById(R.id.wechat).setOnClickListener(this);
        findViewById(R.id.back).setOnClickListener(this);

        qqGroupTv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        qqGroupTv.getPaint().setAntiAlias(true);//抗锯齿

        qqTv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        qqTv.getPaint().setAntiAlias(true);//抗锯齿
    }

    private String getAppVersionName() {
        try {
            String pkName = this.getPackageName();
            String versionName = this.getPackageManager().getPackageInfo(pkName, 0).versionName;
            return versionName;
        } catch (Exception e) {
        }

        return null;
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.qq_group:
                joinQQGroup(PainterConfig.QQ_GROUP_ID);
                break;
            case R.id.qq:
                //submitFeedback();
                joinQQ(PainterConfig.QQ_ID);
                break;
            case R.id.wechat:
                break;
        }
    }

    private void joinQQGroup(String qq) {
        try {
            String url = "mqqapi://card/show_pslcard?src_type=internal&version=1&uin=" + qq + "&card_type=group&source=qrcode";
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, "没有安装QQ!", Toast.LENGTH_SHORT).show();
        }
    }

    private void joinQQ(String qq) {
        try {
            String url = "mqqwpa://im/chat?chat_type=wpa&uin="+qq;
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, "没有安装QQ!", Toast.LENGTH_SHORT).show();
        }
    }
}
